<?php
class NewController extends Controller {
    public $metaDescription = null;
    public $metaKeywords = null;
    public $linkCanoncical = null;
    public $title = null;
    public $layout = "column_project";

    public function actionIndex(){        
        $url = new Url();     
        $array_input['project_id'] = $_SESSION['project_pm']['project_id'];
        $data = News::getRowByProjectID($_SESSION['project_pm']['project_id']);        
        $this->render('index',array("data"=>$data));
    }

    public function actionDetail(){                
        $url = new Url();     
        $new_id = isset($_GET["new_id"])?mysql_escape_string($_GET["new_id"]):"";        
        $data = News::getRowById($new_id);        
        $this->render('detail',array("data"=>$data));
    }
    
    public function actionAdd(){
        $url = new Url();     
        $this->render('add',array());
    }
    
    public function actionAjaxAddNew(){            

        $news_title = isset($_POST["news_title"])?mysql_escape_string($_POST["news_title"]):"";
        $new_description = isset($_POST["new_description"])?mysql_escape_string($_POST["new_description"]):"";
        $new_content = isset($_POST["new_content"])?mysql_escape_string($_POST["new_content"]):"";
        
        $array_input['project_id'] = $_SESSION['project_pm']['project_id'];
        $array_input['new_title'] = $news_title;
        $array_input['new_description'] = $new_description;                
        $array_input['new_content'] = $new_content;                
        $array_input['new_create_user'] = $_SESSION['user_pm']['user_id'];                
        $array_input['new_create_date'] = time();                

        $array_activity['project_id'] = $_SESSION['project_pm']['project_id'];
        $array_activity['activity_user_id'] = $_SESSION['user_pm']['user_id'];                
        $array_activity['activity_name'] = "$news_title (tạo mới)";
        $array_activity['activty_type'] = 5;
        $array_activity['activity_update_time'] = time();        
        $log = Activity::insertObject($array_activity);    
        
        $last_id = News::insertObject($array_input);
        if($last_id !=0){            
            echo 1;                                           
        }else{
            echo 0;
        }
    }

}